package com.lakeworks.web.controller.core;

import com.lakeworks.common.annotation.Log;
import com.lakeworks.common.core.controller.BaseController;
import com.lakeworks.common.core.domain.AjaxResult;
import com.lakeworks.common.core.page.TableDataInfo;
import com.lakeworks.common.enums.BusinessType;
import com.lakeworks.domain.OprMerchandise;
import com.lakeworks.service.IOprMerchandiseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品信息Controller
 *
 * @author lake
 * @date 2023-02-08
 */
@Controller
@RequestMapping("/system")
public class OprMerchandiseController extends BaseController {
    private String prefix = "system/merchandise";

    @Autowired
    private IOprMerchandiseService oprMerchandiseService;

    @GetMapping()
    public String merchandise() {
        return prefix + "/merchandise";
    }

    /**
     * 查询商品信息列表
     */
    @PostMapping("/merchandises")
    @ResponseBody
    public TableDataInfo list(OprMerchandise oprMerchandise) {
        startPage();
        List<OprMerchandise> list = oprMerchandiseService.selectOprMerchandiseList(oprMerchandise);
        return getDataTable(list);
    }

//    /**
//     * 导出商品信息列表
//     */
//    @Log(title = "商品信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    @ResponseBody
//    public AjaxResult export(OprMerchandise oprMerchandise)
//    {
//        List<OprMerchandise> list = oprMerchandiseService.selectOprMerchandiseList(oprMerchandise);
//        ExcelUtil<OprMerchandise> util = new ExcelUtil<OprMerchandise>(OprMerchandise.class);
//        return util.exportExcel(list, "商品信息数据");
//    }

    /**
     * 新增商品信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存商品信息
     */
    @Log(title = "商品信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OprMerchandise oprMerchandise) {
        return toAjax(oprMerchandiseService.insertOprMerchandise(oprMerchandise));
    }

    /**
     * 修改商品信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        OprMerchandise oprMerchandise = oprMerchandiseService.selectOprMerchandiseById(id);
        mmap.put("oprMerchandise", oprMerchandise);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品信息
     */
    @Log(title = "商品信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OprMerchandise oprMerchandise) {
        return toAjax(oprMerchandiseService.updateOprMerchandise(oprMerchandise));
    }
}
